/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

using System;

using MetaExpression = argot.meta.MetaExpression;
using MetaSequence = argot.meta.MetaSequence;


namespace argot
{
	
	public class TypeReaderAuto 
	:TypeReader
	{
		private TypeConstructorAuto _constructor;
		
		public TypeReaderAuto(System.Type clss)
		{
			_constructor = new TypeConstructorAuto(clss);
		}
		
		public virtual System.Object Read(TypeInputStream inStream, TypeElement element)
		{
			if (!(element is MetaExpression))
			{
				throw new TypeException("TypeReaderAuto: required TypeDefinition to read data.");
			}
			
			MetaExpression metaDefinition = (MetaExpression) element;
			if (metaDefinition is MetaSequence)
			{
				MetaSequence sequence = (MetaSequence) metaDefinition;
				Object[] objects = (Object[]) sequence.DoRead( inStream );
				return _constructor.Construct(objects);
			}
			else
			{
				throw new TypeException("TypeReaderAuto: can not read unknown type");
			}
		}
	}
}